package org.noote.libs.roby.configuration;

import java.util.Calendar;

public final class PositionMarker {

	private Calendar creationDate = Calendar.getInstance();
	
	private float compass; // boussole
	
	private float magnetic_x; // orientation magnetique
	private float magnetic_y;
	private float magnetic_z;
	
	private double gps_longitude; // GPS
	private double gps_latitude;
	private double gps_altitude;
	private float gps_speed;

	private float velocity_x; // velocite (accelerometre)
	private float velocity_y;
	private float velocity_z;
	
	private String comment; // commentaire
	
	public PositionMarker(Calendar creationDate, float compass,
			float magnetic_x, float magnetic_y, float magnetic_z, 
			double gps_longitude, double gps_latitude, double gps_altitude,
			float gps_speed,
			float velocity_x, float velocity_y, float velocity_z) {
		this.creationDate = creationDate;
		this.compass = compass;
		this.magnetic_x = magnetic_x;
		this.magnetic_y = magnetic_y;
		this.magnetic_z = magnetic_z;
		this.gps_longitude = gps_longitude;
		this.gps_latitude = gps_latitude;
		this.gps_altitude = gps_altitude;
		this.gps_speed = gps_speed;
		this.velocity_x = velocity_x;
		this.velocity_y = velocity_y;
		this.velocity_z = velocity_z;
	}
	
	
	public static PositionMarker valueFrom(String sData)
	{
		float compass=0, mx=0, my=0, mz=0;
		double longitude=0, latitude=0;
		double altitude=0;
		float speed=0;
		float vx=0, vy=0, vz=0;
		Calendar date=Calendar.getInstance();
			
		String [] datas = sData.split("\\,");
		for(String data : datas)
		{
			String [] values = data.split("\\=");
			if(values.length==2)
			{
				String sWhat = values[0].trim();
				String sVal = values[1].trim();
				if(sWhat.equalsIgnoreCase("CP"))
					compass=Float.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("MX"))
					mx=Float.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("MY"))
					my=Float.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("MZ"))
					mz=Float.valueOf(sVal);		
				else if(sWhat.equalsIgnoreCase("LG"))
					longitude=Double.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("LT"))
					latitude=Double.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("AL"))
					altitude=Double.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("SP"))
					speed=Float.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("VX"))
					vx=Float.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("VY"))
					vy=Float.valueOf(sVal);
				else if(sWhat.equalsIgnoreCase("VZ"))
					vz=Float.valueOf(sVal);
			}
		}
		        
		return new PositionMarker(date, compass, mx, my, mz, longitude, latitude, altitude, speed, vx, vy, vz);
	}
	
	public String formatTo()
	{
		String sRet = "CP="+getCompass()+",MX="+getMagneticX()+",MY="+getMagneticY()+",MZ="+getMagneticZ();
		sRet+=",LG="+getLongitude()+",LT="+getLatitude()+",AL="+getAltitude();
		sRet+=",SP="+getSpeed()+",VX="+getVelocityX()+",VY="+getVelocityY()+",VZ="+getVelocityZ();
		return sRet;
	}
	
	public final Calendar getCreationDate() {
		return creationDate;
	}
	public final float getCompass() {
		return compass;
	}
	public final float getMagneticX() {
		return magnetic_x;
	}
	public final float getMagneticY() {
		return magnetic_y;
	}
	public final float getMagneticZ() {
		return magnetic_z;
	}
	public final double getLongitude() {
		return gps_longitude;
	}
	public final double getLatitude() {
		return gps_latitude;
	}
	public final double getAltitude() {
		return gps_altitude;
	}
	public final float getSpeed() {
		return gps_speed;
	}
	public final float getVelocityX() {
		return velocity_x;
	}
	public final float getVelocityY() {
		return velocity_y;
	}
	public final float getVelocityZ() {
		return velocity_z;
	}
	public final String getComment() {
		return comment;
	}
	public final void setComment(String comment) {
		this.comment = comment;
	}
}